package com.ericsson.rm.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ericsson.rm.model.EmpDetail;
import com.ericsson.rm.vo.ResourceInsertVO;

@Repository
public class InsertResourceDaoImpl implements InsertResourceDao {
	

	@PersistenceContext
	EntityManager entityManager;
	

	@Override
	@Transactional(propagation=Propagation.REQUIRES_NEW)
	 public void insertResourceToDB(ResourceInsertVO vo) {
		try{
	//	entity.getTransaction();
		EmpDetail  emp = new EmpDetail();
		emp.setDateOfJoin(vo.getDateOfjoin());     
		emp.setEmailID(vo.getEmailID());
		emp.setEmpfirstname(vo.getEmpfirstname());
		emp.setEmplastname(vo.getEmplastname());
		emp.setJobStage(vo.getJobStage());
		emp.setLineManager(vo.getLineManager());
		emp.setPhNum(vo.getPhNum());
		emp.setSignum(vo.getSignum());
		emp.setYearsOfExp(vo.getYearsOfExp());
		emp.setEmpID(vo.getEmpID());
		entityManager.persist(emp);
		entityManager.flush();
		entityManager.close();
		
	    }
		catch(Exception e){
			e.printStackTrace();
		}
	}


//	public EntityManagerFactory getEntityManager() {
//		return entityManager;
//	}
//
//
//	public void setEntityManager(EntityManagerFactory entityManager) {
//		this.entityManager = entityManager;
//	}
//	
	
	
	
	
}
